import request from '@/utils/request.js';
import { setting } from '@/config/setting';
const { tokenName } = setting;

/**
 * java后台登录 async 异步编程模型
 */
export const login = async (data) => {
  return request({
    url: '/api/login',
    method: 'post',
    data,
  });
};

/**
 * java获取用户信息
 */
export const getUserInfo = () => {
  return request({
    url: '/api/user/info',
    method: 'get'
  });
};

/**
 * 退出
 */
export const logout = () => {
  return request({
    url: '/api/logout',
    method: 'post',
  });
};

/**
 * 注册
 */
export const register = async () => {
  return request({
    url: '/api/register',
    method: 'post',
  });
};

/**
 * 分页数据查询
 * @param {Object} params
 */
export function dataApi(params) {
  return request({
    url: '/api/user/data',
    method: 'get',
    params: params
  })
}

/**
 * 新增接口
 * @param {Object} data
 */
export function addApi(data){
  return request({
    url: '/api/user',
    method: 'post',
    data: data
  })
}

/**
 * 修改接口
 * @param {Object} data
 */
export function updateApi(data){
  return request({
    url: '/api/user',
    method: 'put',
    data: data
  })
}

/**
 * 根据主键查询
 * @param {Object} id
 */
export function findByIdApi(id){
  return request({
    url: '/api/user/'+id,
    method: 'get'
  })
}

/**
 * 删除
 * @param {Object} id
 */
export function  removeApi(ids){
  return request({
    url: '/api/user/'+ids,
    method: 'delete'
  })
}